# Copyright (c) 2022，Horizon Robotics.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import LaunchConfiguration
from ament_index_python import get_package_share_directory


def generate_launch_description():
    return LaunchDescription([
        # 启动图片发布pkg
        DeclareLaunchArgument(
            'device',
            default_value='F37',
            description='mipi camera device'),
        IncludeLaunchDescription(
            PythonLaunchDescriptionSource(
                os.path.join(
                    get_package_share_directory('mipi_cam'),
                    'launch/mipi_cam.launch.py')),
            launch_arguments={
                'mipi_image_width': '1920',
                'mipi_image_height': '1080',
                'mipi_io_method': 'shared_mem',
                'mipi_video_device': LaunchConfiguration('device')
            }.items()
        ),
        # 启动HDMI图像显示pkg
        Node(
            package='hobot_hdmi',
            executable='hobot_hdmi',
            output='screen',
            parameters=[
                {"io_method": "shared_mem"},
                {"sub_img_topic": "/hbmem_img"},
            ],
            arguments=['--ros-args', '--log-level', 'error']
        ),
    ])